<template>
  <div id="app">
    <!-- 使用 keep-alive 包裹需要缓存的页面 -->
    <transition name="transition">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"/>
      </keep-alive>
    </transition>
    <!-- 非缓存的页面直接渲染 -->
    <transition name="transition">
      <router-view v-if="!$route.meta.keepAlive"/>
    </transition>
  </div>
</template>

<script>

export default{
  computed:{
    key(){
      return this.$route.query.id
    }
  },
  data() {
    return {
      idleTimeout: null
    };
  },
  mounted() {
    // 
    localStorage.setItem('clientId','a43f29e1a527719cb9e941d301116b4f')
    // 设置事件监听以检测用户的活动
    this.idleTimeout = setTimeout(() => {
      this.userIsIdle();
    }, 1000 * 900); // 假设60秒无操作为"长时间"
 
    document.addEventListener('mousemove', this.userIsActive);
    document.addEventListener('keydown', this.userIsActive);
  },
  beforeDestroy() {
    // 清除定时器和事件监听
    clearTimeout(this.idleTimeout);
    document.removeEventListener('mousemove', this.userIsActive);
    document.removeEventListener('keydown', this.userIsActive);
  },
  methods: {
    userIsActive() {
      clearTimeout(this.idleTimeout);
      this.idleTimeout = setTimeout(() => {
        this.userIsIdle();
      }, 1000 * 900);
    },
    userIsIdle() {
      // 用户长时间没有操作的逻辑
      console.log('用户长时间没操作');
      console.log(this)
      // 判断当前是否是首页
      if(this.$route.path != '/'){
        // 跳转首页
        this.$router.push('/');
      }
    }
  }
}
</script>


<style lang="less">
*{
  font-family: 'Bold';
}
#app{
  width: 100%;
  height: 1920px;
}
body{
  padding: 0;
  margin: 0;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -khtml-user-select: none;
  user-select: none;
}

img {
   -webkit-user-drag: none;

  -webkit-user-select: none;

  -moz-user-select: none;

  -ms-user-select: none;

  user-select: none;
}
// #app {
//   width: 100%;
// }
// @media screen and (max-width:768px){
//   #app {
//     width: 1920px;
//   }
// }
/* 隐藏垂直滚动条 */

body::-webkit-scrollbar {
  width: 0;
}

/* 隐藏水平滚动条 */
div::-webkit-scrollbar {
  height: 0;
}

// .transition-enter,.transition-enter-active,.v-enter-to,.v-leave,.v-leave-active,.v-leave-to


.transition-enter-active,
.transition-leave-active {
  transition: opacity 0.5s;
}

.transition-enter-from,
.transition-leave-to {
  opacity: 0;
  
}

.FONT{
  background: -webkit-linear-gradient(top, #7875FC, #C4AAFF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
}


</style>
